<html>
<head>
    <base href="<%=basePath%>">
    <title>人员信息列表</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <script type="text/javascript" src="${springMacroRequestContext.contextPath}/js/user/userList.js"></script>
<script type="text/javascript">
    $(function () {
        $("#addUser").click(function () {
            alert("addUser");
        });
    };
    alert(111);
    var url;
    function newUser(){
        alert(1);
        $('#dlg').dialog('open').dialog('setTitle','新增');
        $('#fm').form('clear');
        url = 'UserServlet?f=add';
    }
    function editUser(){
        var row = $('#mTb').datagrid('getSelected');
        if (row){
            $('#dlg').dialog('open').dialog('setTitle','修改');
            $('#fm').form('load',row);
            url = 'UserServlet?f=update&id=' + row.id;
        }
    }
    function saveUser(){
        $('#fm').form('submit',{
            url: url,
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
                var result = eval('('+result+')');
                if (result.success){
                    $.messager.show({
                        title: '提示',
                        msg: result.message
                    });
                    $('#dlg').dialog('close');        // close the dialog
                    $('#mTb').datagrid('reload');    // reload the user data
                } else {
                    $.messager.show({
                        title: '提示',
                        msg: result.message
                    });
                }
            }
        });
    }
    function removeUser(){
        var row = $('#mTb').datagrid('getSelected');
        if (row){
            $.messager.confirm('确认','您确定要删除吗？',function(r){
                if (r){
                    $.post('UserServlet?f=delete',{id:row.id},function(result){
                        if (result.success){
                            $.messager.show({    // show error message
                                title: '提示',
                                msg: result.message
                            });
                            $('#mTb').datagrid('reload');    // reload the user data
                        } else {
                            $.messager.show({    // show error message
                                title: '提示',
                                msg: result.message
                            });
                        }
                    },'json');
                }
            });
        }
    }
    function doSearch(){
        $('#mTb').datagrid('load',{
            name: $('#username').val(),
            xueli: $('#userxueli').val()
        });
    }
</script>

<body>
<table id="mTb"
       class="easyui-datagrid" width="100%"
       url="${springMacroRequestContext.contextPath}/user/list"
       toolbar="#toolbar" pagination="true"
       rownumbers="true" fitColumns="true" singleSelect="true"
       pageSize="5"
       pageList="[3,5,8,10]" method="get">
    <thead>
    <tr>
        <th field="id" width="50" data-options="hidden: true">编号</th>
        <th field="name" width="50">姓名</th>
        <th field="userId" width="50">用户ID</th>
        <th field="userAccount" width="50">账号</th>
        <th field="password" width="50">密码</th>
        <th field="sex" width="50">性别</th>
        <th field="address" width="50">地址</th>
    </tr>
    </thead>
</table>

<div id="toolbar">
    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" id="addUser" onclick="newUser()">新增</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">修改</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeUser()">删除</a>
</div>

<div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
     closed="true" buttons="#dlg-buttons">
    <div class="ftitle">用户信息</div>
    <form id="fm" method="post" novalidate>
        <div class="fitem">
            <label>姓名:</label>
            <input name="name" class="easyui-validatebox" required="true">
        </div>
        <div class="fitem">
            <label>密码:</label>
            <input name="pass" class="easyui-validatebox" required="true">
        </div>
        <div class="fitem">
            <label>性别:</label>
            <input name="sex" class="easyui-validatebox" required="true">
        </div>
        <div class="fitem">
            <label>年龄:</label>
            <input name="age" class="easyui-validatebox" required="true">
        </div>
        <div class="fitem">
            <label>学历:</label>
            <input name="xueli" class="easyui-validatebox" required="true">
        </div>
        <div class="fitem">
            <label>地址:</label>
            <input name="address" class="easyui-validatebox" required="true">
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveUser()">提交</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
</div>

</body>
</html>